﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using Tisbi.LawFirm.DAL.Models;

namespace Tisbi.LawFirm.UI.ViewModel
{
    public class CasesCRUDViewModel : BaseCRUDItemViewModel<Cases>
    {
        // Default ctor
        public CasesCRUDViewModel(Cases model) : base(model)
        {
        }

        private ObservableCollection<Employees> _employees;

        public ObservableCollection<Employees> Employees
        {
            get { return _employees; }
            set
            {
                _employees = value;
                if (Model.Employees != null)
                {
                    SelectedEmployees = Employees.First(x => x.Id == Model.Employees.Id);
                }
                RaisePropertyChanged(() => Employees);
            }
        }

        public Employees SelectedEmployees
        {
            get { return Model.Employees; }
            set
            {
                Model.Employees = value;
                RaisePropertyChanged(() => SelectedEmployees);
            }
        }

        public string Title
        {
            get { return Model.Title; }
            set
            {
                Model.Title = value;
                RaisePropertyChanged(() => Title);
            }
        }

        public override string Error
        {
            get
            {
                return this["SelectedEmployees"] + "\n" + this["Title"];
            }
        }

        public override string this[string columnName]
        {
            get
            {
                string result = string.Empty;
                switch (columnName)
                {
                    case "SelectedEmployees":
                        if (SelectedEmployees == null) result = "Поле 'Ответственный сотрудник' обязательное";
                        break;
                    case "Title":
                        if (string.IsNullOrWhiteSpace(Model.Title)) result = "Поле 'Название дела' обязательное";
                        break;
                }
                return result;
            }
        }
    }
}
